// import { ref, onMounted, onUnmounted } from 'vue'
import { ref } from 'vue'
import { useEventListener } from './enevt'

//按照惯例，组合式函数名以“use”开头
export function useMouse() {
  //被组合式函数封装和管理的状态
  const x = ref(0)
  const y = ref(0)
  //组合式函数可以随时更改其状态
  function update(event: any) {
    x.value = event.pageX
    y.value = event.pageY
  }
  // onMounted(() => window.addEventListener('mousemove', update))
  // onUnmounted(() => window.removeEventListener('mousemove', update))
  useEventListener(window, 'mousemove', update)
  return { x, y }
}